(function() {
	var Ht = {
		data: null,
		init: function() {
			let c = "你好nihaoこん how are you";
			chrome.i18n.detectLanguage(c, function(result) {//TODO   学习
				console.log("isReliable = " + result.isReliable);
				let t = "";
				t = result.languages[0].language;
//				for(let index in result.languages){
//					t += index + ":(";
//					index = result.languages[index];
//					for(let att in index){
//						t += att + ":" + index[att] + "   ";
//					}
//					t += ")";
//					
//				}
				console.log("languages = " + t);
			});
   			console.log("getUILanguage = " + chrome.i18n.getUILanguage());
   			chrome.i18n.getAcceptLanguages(function(languageArray){
			    console.log("languageArray = " + languageArray);
			});
			chrome.storage.sync.get(null, function(items) {
				Ht.data = items;
				if(Ht.data == null) this.data = {te_option_item: 0,way_option_item: 0};
				Ht.initStyle();
			});
			//添加数据
			document.getElementsByClassName("te_option_item").forEach(function(ele) {
				ele.onfocus = function() {
					this.classList.add(".opt-radiobutton-hover");
				}
				ele.onblur = function() {
					this.classList.remove(".opt-radiobutton-hover");
				}
			});
			this.radioClick("te_option_item");
			this.radioClick("way_option_item");
			document.getElementById("saveBtn").onclick = function() {
				this.classList.add("opt-button-active");
				//
				var t = {};
				t["te_option_item"] = document.querySelector(".te_option_item.opt-radiobutton-checked").getAttribute("data-value");
				t["way_option_item"] = document.querySelector(".way_option_item.opt-radiobutton-checked").getAttribute("data-value");
				chrome.storage.sync.set(t, function(){});
				Ht.data = t;
				var t = document.getElementById("saveStatus");
				t.style.display = "";
				t.style.setProperty("-webkit-transition", "opacity 0.4s ease-out");
				t.style.opacity = 1;
				window.setTimeout(function() {
					t.style.opacity = 0
				}, 1500)
				
			}
			document.getElementById("resetBtn").onclick = function() {
				document.querySelector(".te_option_item.opt-radiobutton-checked").classList.remove("opt-radiobutton-checked");
				document.querySelector(".way_option_item.opt-radiobutton-checked").classList.remove("opt-radiobutton-checked");
				Ht.initStyle();
			}
		},
		initStyle: function() {
			document.getElementsByClassName("te_option_item")[this.data["te_option_item"]==null?0:this.data["te_option_item"]].classList.add("opt-radiobutton-checked");
			document.getElementsByClassName("way_option_item")[this.data["way_option_item"]==null?0:this.data["way_option_item"]].classList.add("opt-radiobutton-checked");
		},
		radioClick: function(className) {
			document.getElementsByClassName(className).forEach(function(ele, index) {
				ele.onclick = function() {
					if(this.classList.contains("opt-radiobutton-checked") == false) { //没选中
						//改变样式
						document.querySelector("." + className + ".opt-radiobutton-checked").classList.remove("opt-radiobutton-checked");
						this.classList.add("opt-radiobutton-checked");
					}
				}
			});
		}
	};
	HTMLCollection.prototype.forEach = function(callback) {
		[].slice.call(this).forEach(callback);
	};
	document.addEventListener("DOMContentLoaded", function() {
		Ht.init();
	});
	//	var teOptionItemEles = document.getElementsByClassName("te_option_item");
	//	var wayOptionItemEles = document.getElementsByClassName("way-option -item");
	//	var saveBtnEle = document.getElementById("saveBtn");
	//	var resetBtnEle = document.getElementById("resetBtn");
	//	var saveStatusEle = document.getElementById("saveStatus");
})();